home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0118_Fader in textmode.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-24  |  2KB  |  96 lines

  1. Unit FadeUnit;          { called FadeUnit.Pas }
  2.  
  3. { This unit does fading for text/graph modes }
  4.  
  5. interface
  6.  
  7. procedure InitCol; { gets the current palette and saves it }
  8. procedure FadeOut(Duration : byte);   { lowers/increases the brightness, }
  9. procedure FadeIn(Duration : byte);    { duration determines the time it takes}
  10. procedure SetBrightness(Brightness : byte); { sets the brightness to brightnes}
  11.  
  12. implementation
  13.  
  14. uses Crt; { use Delay procedure from there }
  15.  
  16. const
  17. PelIdxR  = $3C7; { Port to read from }
  18. PelIdxW  = $3C8; { Port to write to }
  19. PelData  = $3C9; { Dataport }
  20. Maxreg   = 63;   { Set to 255 for graphmode }
  21. MaxInten = 63;
  22.  
  23. type
  24. TRGB = record R, G, B : byte end;
  25.  
  26. var
  27. Col : array[0..MaxReg] of TRGB;
  28. I : byte;
  29.  
  30. Procedure GetCol(ColNr : byte; var R, G, B : byte); assembler;
  31. Asm
  32. MOV DX,PelIdxR
  33. MOV AL,ColNr
  34. OUT DX,AL
  35. MOV DX,PelData
  36. LES SI,R
  37. IN AL,DX
  38. MOV BYTE PTR [ES:SI],AL
  39. LES SI,G
  40. IN AL,DX
  41. MOV BYTE PTR [ES:SI],AL
  42. LES SI,B
  43. IN AL,DX
  44. MOV BYTE PTR [ES:SI],AL
  45. End; { GetCol }
  46.  
  47. Procedure SetCol(ColNr, R, G, B : byte); assembler; { Change just one color }
  48. Asm
  49. MOV DX,PelIdxW
  50. MOV AL,ColNr
  51. OUT DX,AL
  52. MOV DX,PelData
  53. MOV AL,R
  54. OUT DX,AL
  55. MOV AL,G
  56. OUT DX,AL
  57. MOV AL,B
  58. OUT DX,AL
  59. End; { SetCol }
  60.  
  61. Procedure InitCol; { Save initial palette }
  62. Begin
  63. for I := 0 to MaxReg do GetCol(I, Col[I].R, Col[I].G, Col[I].B)
  64. End; { InitCol }
  65.  
  66. Procedure SetBrightness;
  67. Begin
  68. for I := 0 to MaxReg do
  69. SetCol(I,
  70. Col[I].R * Brightness div MaxInten,
  71. Col[I].G * Brightness div MaxInten,
  72. Col[I].B * Brightness div MaxInten)
  73. End; { SetBrightness }
  74.  
  75. Procedure FadeOut;
  76. var I : byte;
  77. Begin
  78. for I := MaxInten downto 0 do
  79. begin
  80. SetBrightness(I);
  81. Delay(Duration)
  82. end
  83. End; { FadeOut }
  84.  
  85. Procedure FadeIn;
  86. var I : byte;
  87. Begin
  88. for I := 0 to MaxInten do
  89. begin
  90. SetBrightness(I);
  91. Delay(Duration)
  92. end
  93. End; { FadeIn }
  94.  
  95. End. { FADEUNIT.PAS }
  96.